package com.rexense.beacon.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

@Data
@Builder
@AllArgsConstructor
public class Label implements Serializable, Comparable<Label> {

    private double x;

    private double y;

    private String xs;

    private String ys;

    private String updateMsgId;

    private long lastUpdate;

    private String labelId;

    public Label() {
    }

    public Label init() {
        this.xs = BigDecimal.valueOf(x).setScale(10, RoundingMode.HALF_UP).toString();
        this.ys = BigDecimal.valueOf(y).setScale(10, RoundingMode.HALF_UP).toString();
        return this;
    }

    @Override
    public int compareTo(Label o) {
        return Long.compare(Long.parseLong(updateMsgId), Long.parseLong(o.getUpdateMsgId()));
    }

    @Override
    public boolean equals(Object o) {
        System.out.println("eq");
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Label label = (Label) o;
        return updateMsgId.equals(label.updateMsgId) &&
                labelId.equals(label.labelId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(updateMsgId, labelId);
    }
}
